home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
prog
/
cmcalc.zip
/
CMCALC.DOC
< prev
next >
Wrap
Text File
|
1991-10-22
|
22KB
|
505 lines
*** COMPUTER MATH CALCULATOR ***
*** FOR THE HP 95LX ***
Copyright (c) 1991 by Eugene Dorr
All rights reserved.
CMCALC is distributed in an archive called CMCALC.ZIP. When "unzipped", you
should have three files:
CMCALC.DOC -- this documentation file
CMCALC.EXM -- executable file
APNAME.LST -- system manager application list
CMCALC is a system-manager compliant application which provides a rich set
of computer-science-oriented integer manipulations. It features variable
word size (from 1 to 32 bits), selectable complement modes (unsigned, 1's
complement, and 2's complement), four number bases (binary, octal, decimal
and hexadecimal), and visible carry and overflow indicators. Only RPN
entry is supported.
Because CMCALC is "system-manager compliant" it can be started and used along
with all other system-manager compliant applications, including the built-in
applications. You can switch between these applications without quitting any
of them, and when you return to an application, you are returned right where
you were when you left. Of course, this also means that CMCALC will operate
ONLY on HP 95LX computers.
Installing CMCALC
-----------------
Basic installation of CMCALC is easy:
(1) Copy CMCALC.EXM to the root directory on the HP 95's drive C:
(2) Copy APNAME.LST to the _DAT subdirectory on the HP 95's drive C:
(3) Quit all active applications and reboot the HP 95 by pressing
CTRL + ALT + DEL.
(4) Start CMCALC by holding down the ALT key and pressing the blue
HP CALC key.
If you already have an APNAME.LST file on your drive C:, then just use the
built-in MEMO application to add the following line to your existing
APNAME.LST file:
C:CMCALC.EXM,C300,CompMathCalc
If you want to install CMCALC on a RAM card, then the APNAME.LST file must
be copied to the root directory on drive A:.
Using CMCALC
------------
To start CMCALC once it has been installed, hold down the ALT key and press
the blue HP CALC key. To quit CMCALC, press MENU, Q. CMCALC uses the HP 95
calculator paradigm, so if you are familiar with using the built-in HP 95
calculator, operation of CMCALC should be straight-forward.
CMCALC uses the RPN mode of data entry. This documentation assumes that you
are familiar with RPN; if you are not, it is discussed in Appendix D of the
HP 95LX User's Guide. The CMCALC calculator operates on integers. If you
need to operate on floating-point numbers, you can use the HP 95 built-in
calculator.
Controlling How CMCALC Works
----------------------------
You can control how CMCALC operates in several ways: you can specify how many
bits will be used to store numbers (the WORD SIZE -- from 1 to 32 bits); you
can specify what complement mode is to be used (the complement mode affects the
results of arithmetic functions, and the display of numbers in decimal mode),
you can choose the number base you wish numbers to be displayed in (base 2 --
binary, base 8 -- octal, base 10 -- decimal, or base 16 -- hexadecimal); and
whether you want leading zeros to be displayed. All of these features are
controlled using MENUs.
For each of the following procedures, the operation may be aborted before it
has been completed by pressing ESC once (if at the first level menu) or
twice.
WORDSIZE
To set the wordsize, press MENU W(ordsize). Type in the number of bits per
word (in decimal) and press ENTER. You may specify any wordsize between 1
and 32, inclusive. Except in unsigned mode, the high bit of a word indicates
the sign of a number.
COMPLEMENT MODE
To set the complement mode, press MENU C(omplement). A secondary menu appears,
which gives you the option of Unsigned mode, 1's complement mode, or 2's
complement mode. Press U to select unsigned mode, 1 to select 1's complement
mode, or 2 to select 2's complement mode. In unsigned mode all numbers are
considered to be positive.
BASE
To set the base used for displaying numbers, press MENU B(ase). A secondary
menu appears, which gives you the option of Binary, Octal, Decimal, or
Hexadecimal. When numbers are displayed in decimal mode, a minus sign (-)
is used to indicate negative numbers, and leading zeros are never displayed,
even if that option is selected.
LEADING ZEROS
You may prefer to see numbers displayed with leading zeros. This option can
be toggled on and off by pressing MENU O(ptions) L(eadingZeros). In decimal
mode, leading zeros are never displayed.
STATUS
To see the current number base, word size, and complement mode, press MENU
S(tatus). A window will appear which show the current settings. Press ESC
to remove the window.
ERASE
MENU E(rase) causes a secondary menu to be displayed, which gives you the
option of zeroing the calcline (the X register), the storage registers
(registers 0..9 and A..F), the stack (registers X, Y, Z and T), or the
flags (Carry and Overflow).
Functions
---------
In the following descriptions, upper case X, Y, Z and T refer to the stack
registers, lower case x, y, z and t refer to the values contained in the
corresponding stack registers. No stack movement occurs unless explicitly
stated. The Carry and Overflow flags are unaffected unless stated otherwise.
The Carry flag is usually used to indicate the value of a bit in the result
which could not be accomodated in the current size of the register, for
example, a carry during addition, a borrow during subtraction, or a bit
shifted out of a register during a shift function. The Overflow flag is
used to indicate that the result could not be expressed within the current
register size and complement mode. For example, if the wordsize is 8 and the
complement mode is 2's complement, then the largest positive number which can
be expressed is 127, and the largest negative number which can be expressed
is -128. If the CHS (change sign) function is applied to -128, then the
Overflow flag will be set, since +128 cannot be expressed in 8 bits.
Some functions (the ones which refer to bit positions) use the absolute
(positive) value of x. This is indicated by the notation |x|.
As with the HP 95 built-in calculator, many functions are assigned to F-keys,
which are labelled on the last two lines of the display. Four groups of
functions are available, and the different groups are accessed by pressing
F10 (labelled 'More'). In the following descriptions, functions which are
assigned to Fkeys carry the notation '(Fkey)'.
ARITHMETIC FUNCTIONS
+ Add -- (+)
x is added to y, result returned in X. The stack drops. Carry and
Overflow are set as appropriate for the complement mode.
- Subtract -- (-)
x is subtracted from y, result returned in X. The stack drops. Carry
and Overflow are set as appropriate for the complement mode.
* Multiply -- (*)
x is multiplied by y, result returned to X, the stack drops. Overflow
is sometimes set if the result cannot be represented in the current
wordsize and complement mode. The overflow flag is not a reliable
indication of whether an overflow occured with this function.
/ Divide -- (/)
The quotient of y divided by x, result returned in X. The stack
drops. The Carry flag is set if there is a remainder, otherwise it is
cleared. Overflow is set only in 2's complement mode when the largest
possible negative number is divided by -1. In all other cases it is
cleared. The function is inhibited and an error message is displayed
if x is 0 or -0.
ABS Absolute value -- (Fkey)
If x is negative (this can only be true if the complement mode is not
unsigned) then it is made positive, if possible, the result is
returned to X, and Overflow is reset. If it is not possible to make x
positive (i.e. the complement mode is 2's complement, and x is the
largest possible negative number), then X remains unchanged and the
Overflow flag is set.
RMD Remainder -- (Fkey)
y is divided by x, the quotient is discarded, and the remainder is
returned in X. The stack drops. The function is inhibited and an
error message is displayed if x is 0 or -0.
CHS Change Sign -- (assigned to the 'L' key)
Complements x, result returned in X. Carry and Overflow are set as
appropriate for the complement mode. The function is inhibited and an
error message is displayed in unsigned mode.
BOOLEAN LOGIC FUNCTIONS
AND Bitwise AND -- (Fkey)
Bitwise logical AND of x and y, result returned in X. The stack drops.
OR Bitwise OR -- (Fkey)
Bitwise logical OR of x and y, result returned in X. The stack drops.
XOR Bitwise Exclusive OR -- (Fkey)
Bitwise logical exclusive OR of x and y, result returned in X. The
stack drops.
NOT Bitwise NOT -- (Fkey)
Bitwise logical NOT of x, result returned in X.
BIT-MANIPULATION FUNCTIONS
MASKL Mask left -- (Fkey)
A bit mask of the size specified by |x| is created and placed in the
leftmost positions of X, replacing x.
MASKR Mask right -- (Fkey)
A bit mask of the size specified by |x| is created and placed in the
rightmost positions of X, replacing x.
SB Set bit -- (Fkey)
The bit specified by |x| (x=0 specifies the rightmost bit) is set in y,
the result is returned in X. The stack drops.
CB Clear bit -- (Fkey)
The bit specified by |x| (x=0 specifies the rightmost bit) is cleared
in y, the result is returned in X. The stack drops.
INV Invert bit order -- (Fkey)
The order of the bits in x is reversed, the result is returned in X.
#BIT Bit count -- (Fkey)
The number of 1-bits in x is returned in X.
SHIFT AND ROTATE FUNCTIONS
SL Shift left -- (Fkey)
x is shifted to the left by one position, a zero bit is introduced
into the rightmost bit position, and the result is returned in X.
The Carry flag is set to the value of the leftmost bit of x.
+---+ +----------------+
| | <-- | <----- | <-- 0
+---+ +----------------+
Carry
SR Shift right -- (Fkey)
x is shifted to the right by one position, a zero bit is introduced
into the leftmost bit position, and the result is returned in X.
The Carry flag is set to the value of the rightmost bit of x.
+----------------+ +---+
0 --> | -----> | --> | |
+----------------+ +---+
Carry
SLn Shift left multiple -- (Fkey)
y is shifted to the left by the number of positions specified by |x|,
zero bits are introduced into the vacated rightmost bit positions,
the result is returned in X. The stack drops. The Carry flag is set
to the value of the last bit to be shifted from the leftmost position
of y.
SRn Shift right multiple -- (Fkey)
y is shifted to the right by the number of positions specified by |x|,
zero bits are introduced into the vacated leftmost bit positions,
the result is returned in X. The stack drops. The Carry flag is
set to the value of the last bit to be shifted from the rightmost
position of y.
ASR Arithmetic shift right -- (Fkey)
x is shifted to the right by one position, the leftmost bit retains
its original value, the result is returned in X. The Carry flag is
set to the value of the leftmost bit of x.
+------+
| |
| +----------------+ +---+
+--> | -----> | --> | |
+----------------+ +---+
Carry
LJ Left justify -- (Fkey)
If x<0, then x is shifted left until the leftmost bit contains a one
bit. The result is returned to Y. The number of shifts performed is
returned in X. The stack is lifted. If x=0, the stack is lifted and
X and Y are set to 0.
RL Rotate left -- (Fkey)
x is shifted left by one position, the value of the leftmost bit is
returned in the rightmost bit position, and also in the Carry flag.
The result is returned in X.
+--------------------------+
+---+ | +----------------+ |
| | <---+--- | <----- | <--+
+---+ +----------------+
Carry
RR Rotate right -- (Fkey)
x is shifted right by one position, the value of the rightmost bit is
returned in the leftmost bit position, and also in the Carry flag.
The result is returned in X.
+--------------------------+
| +----------------+ | +---+
+--> | -----> | ---+---> | |
+----------------+ +---+
Carry
RLn Rotate left multiple -- (Fkey)
y is shifted left by |x| positions, and as each bit is shifted out of
the leftmost bit position, it is introduced into the rightmost bit
position, and into the Carry flag. The result is returned in X. The
stack drops.
RRn Rotate right multiple -- (Fkey)
y is shifted right by |x| positions, and as each bit is shifted out of
the rightmost bit position, it is introduced into the leftmost bit
position, and into the Carry flag. The result is returned in X. The
stack drops.
RLC Rotate left through carry -- (Fkey)
x is shifted left one position, the value of the Carry flag is
introduced into the vacated rightmost bit position, and the Carry
flag is set to the value of the bit shifted out of the leftmost
position.
+------------------------------------+
| +---+ +----------------+ |
+--- | | <-- | <----- | <--+
+---+ +----------------+
Carry
RRC Rotate right through carry -- (Fkey)
x is shifted right one position, the value of the Carry flag is
introduced into the vacated leftmost bit position, and the Carry flag
is set to the value of the bit shifted out of the rightmost position.
+------------------------------------+
| +---+ +----------------+ |
+--> | | --> | -----> | ---+
+---+ +----------------+
Carry
RLCn Rotate Left through Carry multiple -- (Fkey)
y is shifted left by |x| positions, and at each shift, the rightmost
bit position receives the value of the Carry bit, and the Carry bit
receives the value of the bit shifted out of the leftmost position.
The result is placed in X. The stack drops.
RRCn Rotate Right through Carry multiple -- (Fkey)
y is shifted right by |x| positions, and at each shift, the leftmost
bit position receives the value of the Carry bit, and the Carry bit
receives the value of the bit shifted out of the rightmost position.
The result is placed in X. The stack drops.
STACK CONTROL OPERATIONS
Rv Roll Down -- (assigned to the 'v' key)
The contents of each stack register is shifted into the next lower
register, and x is shifted into T.
R^ Roll Up -- (assigned to the 'V' key)
The contents of each stack register is shifted into the next higher
register, and t is shifted into X.
x<>y Exchange X and Y -- (assigned to the 'X' key)
The contents of the X and Y registers are exchanged.
NUMBER STORAGE AND RETRIEVAL
STO Store -- (assigned to the 'N' key)
The calculator waits for a register specifier - a digit key (0..9)
or A..F; when a register has been specified, x is stored into that
register. The value may later be recalled to X by pressing RCL
and the same register specifier. x remains in X. The STO operation
may be cancelled before specifying a register, by pressing ESC.
RCL Recall -- (assigned to the 'M' key)
As with STO, RCL must be followed by a register specifier. The
stack is lifted and the value last stored into the specified register
is placed into X. The value remains in the specified register. The
RCL operation may be cancelled before specifying a register by
pressing ESC.
RCL L Last X -- (Press the 'M' (RCL) key, followed by 'L')
Returns to X the value which was in X prior to the last function.
MISCELLANEOUS
SHOW Show X in all bases -- (Fkey)
The value in X is displayed simultaneously in binary, octal, decimal
and hexdecimal. The complement and leading-zeros settings are
observed for each base displayed. This display remains until a key
is pressed. If ESC is pressed, then the SHOW display is erased, and
no action is taken. If any other key is pressed, the SHOW display
is erased, and the action of that key is processed. LastX is not set.
RCL V Display version -- (Press the 'M' key (RCL), followed by 'V')
A window is displayed, which shows the version of CMCALC.
NUMBER ENTRY
0..9 Digits -- Used to enter numbers. The letters A, B, C, D, E and F
A..F are used for digit entry in hexadecimal mode.
ENTER Enter -- (ENTER)
Copies x into Y, and disables stack lift. If entry mode is active,
it is terminated.
<-- Backspace -- (assigned to the backarrow key)
When entry mode is active (the cursor is displayed on the entry
line) the last digit entered is deleted. If no digits remain,
entry mode is terminated. When entry mode is not active, the X
register is set to zero, and stack lift is disabled.
Error Messages
--------------
Divide by zero
A divide (/) or RMD function was attempted when the value in X was
0 or (in 1's complement mode) -0. Division by 0 is undefined.
Exceeds current wordsize
A mask (MASKL or MASKR), bit-addressing (SB or CB), shift multiple
(SLn or SRn), or rotate multiple (RLn or RRn) function was attempted
and |x| was greater than the currently selected word size; or a rotate
through carry multiple (RLCn or RRCn) function was attempted and |x|
was greater than the currently selected word size + 1. You can display
the currently selected word size by pressing MENU S. You can change
the currently selected wordsize by pressing MENU W, entering the
desired wordsize (in decimal), and pressing ENTER.
Current mode is unsigned
You attempted to change the sign (using CHS) of a number, but the
currently selected complement mode is unsigned. A negative number
cannot be expressed in unsigned mode. You can display the currently
selected complement mode by pressing MENU S. You can change the
currently selected complement mode by pressing MENU C, and then
pressing the first character of the desired complement mode.
The HP 95 Calculator Paradigm
-----------------------------
I have tried to make CMCALC adhere to the HP 95 calculator paradigm, but
there are some exceptions:
* Algebraic entry mode is not supported
* STO @ and RCL @ are not supported
* Shift-V performs roll-up
* Square root and inverse are omitted
Since the "B" and "C" keys are used for entering hexadecimal numbers, they are
unavailable for the standard LASTx and x<>y functions. Therefore...
* LASTx is obtained by RCL L
* x<>y is assigned to the X key
CMCALC Compared to the HP-16C
-----------------------------
For those familiar with the HP-16C, CMCALC does not provide programmability,
and omits functions directy related to programmability (there is no indirect
register, no x?y or x?0 comparisons, no flag manipulaton functions, and no
bit test (B?) function). CMCALC also omits floating-point mode, and the
square root function, since these are available in the built-in HP 95
calculator. The three DBL functions have been omitted. Word size is
limited to a maximum of 32 bits. Whereas the HP-16C had a variable number
of registers, CMCALC has a fixed set of 16 registers: 0..9 and A..F.
Problems, Bugs, Comments
------------------------
If you have problems with CMCALC, or have found a bug, or if you wish
to contact me with suggestions for change or improvement (or just a
friendly "hello"), you can contact me on CompuServe (75156.3132).
CMCALC may be freely copied and distributed ONLY in unmodified form, and
you may not charge any fee for it. I neither make nor express any warranty
that CMCALC operates correctly (though I believe it to do so), or that it
is suitable for your purposes (though I hope it is).
Gene Dorr